let App = getApp();

Page({
  data: {
    searchColor: "rgba(0,0,0,0.4)",
    searchSize: "15",
    searchName: "搜索商品",

    scrollHeight: null,
    showView: false,
    arrange: "",

    sortType: 'all',    // 排序类型
    sortPrice: false,   // 价格从低到高

    option: {},
    list: {},

    noList: true,
    no_more: false,

    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (option) {
    let _this = this;

    // 设置商品列表高度
    _this.setListHeight();

    // 记录option
    _this.setData({ option }, function () {
      // 获取商品列表
      _this.getGoodsList(true);
    });

  },

  /**
    * 获取商品列表
    */
  getGoodsList: function (is_super, page) {
    let _this = this;
    App._get('wxappHelp/findAll/1', {
      page: page || 1,
      search: this.data.option.search || '',
    }, function (result) {
      let resultList = result.data
        , dataList = _this.data.list;
      console.info("result", result.data);
      var last_page;
      if (resultList.length) {
        last_page = result.data[0].last_page;
      } else {
        last_page = 0;
      }

      if (is_super === true || typeof dataList.data === 'undefined') {
        // typeof dataList.data === 'undefined'
        let i;
        for (i in resultList) {
          var time = resultList[i].create_time;

          resultList[i].create_time = App.timeformat2(time);
        }
        _this.setData({ list: resultList, noList: false });
        _this.data.list.last_page = last_page;

      } else {
        _this.setData({ 'list.data': dataList.data.concat(resultList.data) });

      }
    });
  },

  /**
   * 设置商品列表高度
   */
  setListHeight: function () {
    let _this = this;
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          scrollHeight: res.windowHeight,
        });
      }
    });
  },



  /**
   * 跳转筛选
   */
  toSynthesize: function (t) {
    wx.navigateTo({
      url: "../category/screen?objectId="
    });
  },



  /**
   * 下拉到底加载数据
   */
  bindDownLoad: function () {
    // 已经是最后一页

    if (this.data.page >= this.data.list.last_page) {

      this.setData({ no_more: true });
      return false;
    }
    this.getGoodsList(false, ++this.data.page);
  },

  /**
   * 设置分享内容
   */
  onShareAppMessage: function () {
    return {
      title: "全部分类",
      desc: "",
      path: "/pages/category/index"
    };
  },

});
